﻿<?php
$error_level = error_reporting(0);
$con = new mysqli('127.0.0.1','root','Winner$123','anli');
if($con){
    $result = mysqli_fetch_assoc(mysqli_query($con,'select store from products where id=1'));
    if($result['store']>0){
        //减库存
        $con->begin_transaction();
        $res =$con->query('update products set store=store-1 where id=1');
        if($res){
            echo '秒杀成功';
        }else{
            echo '秒杀失败';
            $con->rollback();
        }
        $con ->commit();
    }else{
        echo "秒杀结束  商品抢购完成";
    }

}else {
    echo "数据库连接失败";
}




























